<?php


    class CImageToken
    {
	var $m_hSocket;
    
	static function &GetInstance()
	{
	    global $g_hObjects;
	    static $m_hApp = NULL;
					 
	    if(!isset($m_hApp))
	    {
		$m_hApp = new CImageToken();
		$g_hObjects[] = $m_hApp;
		$m_hApp->OnInit();
						
	    }
	    
	    return $m_hApp;
	}
	
	function OnInit()
	{
	}
	
	function OnDestroy()
	{
	}
	
	function Generate($iWidth,$iHeight,$iStrLen)
	{
	    $hPic 	   = imagecreate($iWidth,$iHeight);
	    $hColorWhite   = imagecolorallocate($hPic,255,255,255);
	    $hColorBlack   = imagecolorallocate($hPic,0,0,0);
	    $hColorA       = imagecolorallocate($hPic,190,190,180);
	    $hColorB 	   = imagecolorallocate($hPic,0,0,0);
	    
	    imagefill($hPic,0,0,$hColorWhite);
	    	    
	    for($i=0;$i<40;$i++)
	    {
		$iA = rand(0,$iWidth);
		$iB = rand(0,$iHeight);
		$iC = rand(0,$iWidth);
		$iD = rand(0,$iHeight);
		
		imageline($hPic,$iA,$iB,$iC,$iD,$hColorA);
	    }
	    
	    $szText = RandStr($iStrLen);
	    
	    for($i=0;$i<$iStrLen;$i++)
	    {
		//imagerotate($hPic, mt_rand(-10,10),$hColorWhite);
	    
		imagechar($hPic,6,30+20*$i,$iHeight/4,$szText[$i],$hColorB);
	    }
	    	    
	    //HttpPreventCache();
	    HttpContentType(CONTENT_GIF);
	    
	    imagegif($hPic);
	    imagedestroy($hPic);
	    
	    return $szText;
	}
    }

?>